/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 28463
 * Date: 2022—06—01
 * Time: 14:55
 */
//<T>代表当前类是泛型类
class MyArray2<T> {

    public T[] array = (T[])new Object[10];
    public T getPos(int pos) {
        return array[pos];
    }
    public void setVal(int pos,T val) {
        this.array[pos] = val;
    }
}
public class Test03 {
    public static void main(String[] args) {
        //<>中指定类型,此时这个类里面，只能放这个数据类型的数据
        MyArray2<String> myArray = new MyArray2<String>();
        myArray.setVal(0,"nb");
        myArray.setVal(1,"xawl");

        String s =  myArray.getPos(1);
        String s1 = myArray.getPos(0);
        System.out.println(s);
        System.out.println(s1);

        MyArray2<Integer> myArray2 = new MyArray2<Integer>();
        myArray2.setVal(0,12);
        myArray2.setVal(1,13);
        Integer I = myArray2.getPos(0);
        System.out.println(I);
    }
}
